package jdbc;

import jdk.nashorn.internal.runtime.ECMAException;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class JDBCDemo2 {
    public static void main(String[] args) throws Exception {
        //加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //建立连接，使用驱动管理器获取连接
        Connection connection = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root",
                "root"
        );
        //创建声明
        Statement statement = connection.createStatement();
        String sql="insert into userinfo(username, password, nickname, age)" +
                "    value ('张三','123456','阿三','22')";
        int i = statement.executeUpdate(sql);

        if (i>0){
            System.out.println("插入成功");
        }
        connection.close();

    }
}
